package com.library.dcy.servlet;

import com.library.dcy.entity.BorrowInfo;
import com.library.dcy.entity.PageInfo;
import com.library.dcy.service.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 借书
 */
public class BorrowServlet extends HttpServlet {
    BookServiceImpl bookService=new BookServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/thml;charse=UTF-8");
        req.setCharacterEncoding("UTF-8");
        System.out.println("666");
        String id = (String) req.getSession().getAttribute("id");
        System.out.println(id);
        String curr = req.getParameter("curr");
        if (curr == null || curr == "") {
            curr = "1";
        }
        PageInfo<BorrowInfo> pageborrow = bookService.borrow(Integer.parseInt(id), Integer.parseInt(curr));
        req.setAttribute("page", pageborrow);
        req.getRequestDispatcher("dcy/borrow.jsp").forward(req,resp);
    }
}
